﻿Public Class FormChangeLhj
    Dim objHWSetting As New clsHWSetting
    Dim objProdInfo As New clsProdInfo
    Dim rb_checked_text As String = "全部"
    Private Sub FormChangeLhj_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        getRbChechedText()
        SetLhjList()
        setDgvData()
    End Sub

    Private Sub RadioButtonText_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, RadioButton3.CheckedChanged, RadioButton4.CheckedChanged
        getRbChechedText()
        SetLhjList()
    End Sub

    Private Sub getRbChechedText()
        If RadioButton1.Checked Then
            rb_checked_text = RadioButton1.Text
        End If
        If RadioButton2.Checked Then
            rb_checked_text = RadioButton2.Text
        End If
        If RadioButton3.Checked Then
            rb_checked_text = RadioButton3.Text
        End If
        If RadioButton4.Checked Then
            rb_checked_text = RadioButton4.Text
        End If
    End Sub

    Private Sub SetLhjList()
        Dim dtLHJ As DataTable = objHWSetting.selectAllLHJList(rb_checked_text)
        ListBox1.ValueMember = "equip_id"
        ListBox1.DisplayMember = "equip_id"
        ListBox1.DataSource = dtLHJ
    End Sub

    Private Sub setDgvData()
        Dim dt As DataTable = objProdInfo.getLHList()
        dgv.Font = New Font("UTF-8", 12)
        If dt.Rows.Count > 0 Then
            For Each row As DataRow In dt.Rows
                If DBNull.Value.Equals(row("into_vu_time")) = False And DBNull.Value.Equals(row("lh_total_duration")) = False Then
                    Dim temp_time_length As Double = Double.Parse(row("lh_total_duration"))
                    'Double.Parse(row("time_length_1")) + Double.Parse(row("time_length_2")) + Double.Parse(row("time_length_3"))
                    row("comp_time") = DateTime.Parse(row("into_vu_time")).AddMinutes(temp_time_length).ToString()
                End If
            Next
        End If
        Dim dv As DataView = dt.DefaultView
        dv.Sort = " comp_time Asc"
        Dim dtnew As DataTable = dv.ToTable()
        dgv.AutoGenerateColumns = False
        dgv.DataSource = dtnew
    End Sub

    Private Sub btnChange_Click(sender As Object, e As EventArgs) Handles btnChange.Click
        If MsgBox("确认要更换硫化机吗？", vbYesNo, "提示") = vbYes Then
            If ListBox1.SelectedIndex >= 0 Then
                If dgv.SelectedRows.Count > 0 Then
                    Dim prod_id As String = dgv.SelectedRows(0).Cells("prod_id").Value.ToString()
                    Dim prod_spec_id As String = dgv.SelectedRows(0).Cells("prod_spec_id").Value.ToString()
                    Dim lhj_id As String = dgv.SelectedRows(0).Cells("lhj_id").Value.ToString()
                    Dim rtn As Integer = objProdInfo.changeLHJ(prod_id, prod_spec_id, lhj_id, ListBox1.SelectedValue.ToString())
                    If rtn <> -2 Then
                        MsgBox("更换硫化机成功", vbYes, "提示")
                        getRbChechedText()
                        SetLhjList()
                        setDgvData()
                    Else
                        MsgBox("更换硫化机失败", vbYes, "提示")
                    End If
                Else
                    MsgBox("请选择正在硫化支座的硫化机", vbYes, "提示")
                End If
            Else
                MsgBox("请从空闲硫化机中，选择要切换到的硫化机", vbYes, "提示")
            End If
        End If
    End Sub
End Class